fn main() {
    // 条件判断
    let age = 19;
    let result = if age >= 18 { "成年" } else { "未成年" };
    println!("结果: {}", result);

    // 无限循环
    let mut counter = 0;
    loop {
        counter += 1;
        if counter == 5 {
            // continue; // 结束本次
            break; // 跳出循环
        }
        println!("计数: {}", counter);
    }

    // 条件循环
    let mut n = 1;
    while n <= 5 {
        println!("当前值: {}", n);
        n += 1;
    }

    // 迭代器循环
    let arr = [1, 2, 3];
    // &num拿出引用的值
    for &num in arr.iter() {
        println!("数组元素: {}", num);
    }

    // 范围循环 (包括5)
    // for i in 1..5 不包括5
    for i in 1..=5 {
        println!("范围元素: {}", i);
    }

    // 模式匹配
    let number = 3;
    match number {
        1 => println!("1"),
        2..=5 => println!("2-5"),
        _ => println!("-1"),
    }
}
